package com.mxl.service.cashorder.rule;

import java.util.regex.Pattern;

import com.mxl.common.StringUtil;
import com.mxl.common.helper.ResponseErrorCode;
import com.mxl.common.rule.AbstractRule;
import com.mxl.service.cashorder.dto.CashOrderRequest;

public class MemberSubmitParamCheckRule extends AbstractRule {
	private static final String VERSION = "1.0";

	protected boolean makeDecision(Object obj) throws Exception {
		CashOrderRequest c = (CashOrderRequest) obj;
		if (!Pattern.matches("[\\w-_]{1,50}", c.getOrderId())) {
			c.setMsgId(ResponseErrorCode.ORDERID_IS_NOT_USABLE.getValue());
			return false;
		}
		if (!VERSION.equalsIgnoreCase(c.getVersion())) {
			c.setMsgId(ResponseErrorCode.VERSION_IS_RIGHT.getValue());
			return false;
		}
		if (c.getOrderTime() != null && c.getOrderTime().length() > 14) {
			c.setMsgId(ResponseErrorCode.VERSION_IS_RIGHT.getValue());
			return false;
		}
		if (c.getProductName() != null && c.getProductName().length() > 400) {
			c.setMsgId(ResponseErrorCode.PRODUCT_NAME_OVER_LEN.getValue());
			return false;
		}
		if (c.getExt1() != null && c.getExt1().length() > 1000) {
			c.setMsgId(ResponseErrorCode.EXT1_OVER_LEN.getValue());
			return false;
		}
		if (c.getExt2() != null && c.getExt2().length() > 1000) {
			c.setMsgId(ResponseErrorCode.EXT2_OVER_LEN.getValue());
			return false;
		}
		if (StringUtil.includeTchar(c.getNotifyUrl())) {
			c.setMsgId(ResponseErrorCode.NOTIFY_URL_IS_NOT_USABLE.getValue());
			return false;
		}
		return true;
	}
}
